package com.example.facemanager.config;

import com.example.facemanager.service.BaiduFaceManagerService;
import com.example.facemanager.vo.GroupInfoState;
import com.example.facemanager.vo.ReturnMsg;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author huchenying
 * @Date 2022/8/9 08:57
 * @Description
 */
@Component
public class PreTask implements ApplicationRunner {

    @Autowired
    private BaiduFaceManagerService baiduFaceManagerService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ReturnMsg returnMsg = baiduFaceManagerService.doGetUserGroupList();
        if(returnMsg.getCode() == 200){
//            JSONObject groupList = new JSONObject(returnMsg.getData().toString());
//
//            JSONArray group_id_list = groupList.getJSONArray("group_id_list");
//            group_id_list.forEach(e -> {
//                Memory.groupInfoStates.add(new GroupInfoState(e.toString()));
//            });
            System.out.println("groupInfoStates init successful info -> " + ToStringBuilder.reflectionToString(Memory.getGroupInfoStates()));
        }
    }
}
